<?php

namespace JLPay\Services\Openmerch\Change;

use JLPay\Services\BaseService;
use JLPay\Models\Openmerch\Change\RateInfoChangeRequest;
use JLPay\Models\Openmerch\Change\RateInfoChangeResponse;
use JLPay\Models\Openmerch\Change\MerchInfoChangeRequest;
use JLPay\Models\Openmerch\Change\MerchInfoChangeResponse;
use JLPay\Models\Openmerch\Change\SettleAccountChangeRequest;
use JLPay\Models\Openmerch\Change\SettleAccountChangeResponse;
use JLPay\Models\Openmerch\Change\FixedWithdrawModifyRequest;
use JLPay\Models\Openmerch\Change\FixedWithdrawModifyResponse;
use JLPay\Models\Openmerch\Change\SettleRuleModifyRequest;
use JLPay\Models\Openmerch\Change\SettleRuleModifyResponse;
use JLPay\Models\Openmerch\Change\SignInfoModifyRequest;
use JLPay\Models\Openmerch\Change\SignInfoModifyResponse;

/**
 * 开放商户变更服务
 */
class ChangeService extends BaseService
{
    /**
     * 构造函数
     *
     * @param \JLPay\Core\OrgConfig $config
     */
    public function __construct($config)
    {
        parent::__construct($config);
    }

    /**
     * 获取API URL
     *
     * @param string $requestClass
     * @param string|null $apiPath
     * @return string
     */
    public function getApiUrl(string $requestClass, ?string $apiPath = null): string
    {
        $baseUrl = $this->config->getUrl();
        
        if ($apiPath) {
            return $baseUrl . $apiPath;
        }
        
        // 直接使用Request类中定义的完整API路径
        $apiUrl = constant($requestClass . '::API_URL');
        
        if (!$apiUrl) {
            // 如果没有定义API_URL，使用默认路径
            return $baseUrl . '/open/merch/access';
        }
        
        // 直接返回完整路径
        return $baseUrl . $apiUrl;
    }

    /**
     * 变更费率信息
     *
     * @param RateInfoChangeRequest $request
     * @return RateInfoChangeResponse
     */
    public function changeRateInfo(RateInfoChangeRequest $request): RateInfoChangeResponse
    {
        return $this->post($request, RateInfoChangeResponse::class);
    }

    /**
     * 变更商户信息
     *
     * @param MerchInfoChangeRequest $request
     * @return MerchInfoChangeResponse
     */
    public function changeMerchInfo(MerchInfoChangeRequest $request): MerchInfoChangeResponse
    {
        return $this->post($request, MerchInfoChangeResponse::class);
    }

    /**
     * 变更结算账户
     *
     * @param SettleAccountChangeRequest $request
     * @return SettleAccountChangeResponse
     */
    public function changeSettleAccount(SettleAccountChangeRequest $request): SettleAccountChangeResponse
    {
        return $this->post($request, SettleAccountChangeResponse::class);
    }

    /**
     * 修改商户定点清算
     *
     * @param FixedWithdrawModifyRequest $request
     * @return FixedWithdrawModifyResponse
     */
    public function modifyFixedWithdraw(FixedWithdrawModifyRequest $request): FixedWithdrawModifyResponse
    {
        return $this->post($request, FixedWithdrawModifyResponse::class);
    }

    /**
     * 修改商户结算规则
     *
     * @param SettleRuleModifyRequest $request
     * @return SettleRuleModifyResponse
     */
    public function modifySettleRule(SettleRuleModifyRequest $request): SettleRuleModifyResponse
    {
        return $this->post($request, SettleRuleModifyResponse::class);
    }

    /**
     * 修改商户签约信息
     *
     * @param SignInfoModifyRequest $request
     * @return SignInfoModifyResponse
     */
    public function modifySignInfo(SignInfoModifyRequest $request): SignInfoModifyResponse
    {
        return $this->post($request, SignInfoModifyResponse::class);
    }
} 